package jdk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Rasta01 actually moves.
 * 
 * @author Philip Johnson - original
 * @author D. Korse - derivative
 */
public class TestRasta01DoesMove extends RobotTestBed {
  
  /** True if the robot actually moves. */
  boolean doesMove = false;

  double xPosCurr = 0;
  double yPosCurr = 0;
  
  /**
   * Specifies that SittingDuck and Rasta01 are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,jdk.Rasta01";
  }
  
  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if we've moved.  If so, set the corresponding flag.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    
    double xPos = robot.getX();
    double yPos = robot.getY();
    
    //  Checks to see if the robot actually moves
    if ((xPosCurr != xPos) && (yPosCurr != yPos)) {
      doesMove = true;
      xPosCurr = xPos;
      yPosCurr = yPos;
    }
  }
  
  /**
   * After the battle, check to see that the robot actually moved. 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check That Robot Moves", doesMove);
    
  }
}
